﻿<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>    

<head>

	    
	    
<style type="text/css">  
        .datagrid-header-rownumber,.datagrid-cell-rownumber{  
            width:50px;  
        }  
</style> 
	<script type="text/javascript" src="<c:url value='/easyui/datagrid-scrollview.js'/>"></script>
	<script type="text/javascript" src="<c:url value='/easyui/datagrid-bufferview.js'/>"></script>
	<script type="text/javascript" src="<c:url value='/js/queryesinfo.js?r=a'/>"></script>
	<SCRIPT language=JAVASCRIPT src='<c:url value="/js/grid.js"/>'></SCRIPT>
	<script type="text/javascript">
	
	var twice = ${cfgs["fontsizetwice"]};
	var fontsize = 12;
	var lineheight = 18;
	
	function dgfontsizechange(){
		if (twice > 1){
			
			$(".datagrid-row .datagrid-cell").css("font-size", fontsize*twice+ "px");
			$(".datagrid-row .datagrid-cell").css("line-height", lineheight*twice + "px");

			$(".datagrid-cell-rownumber").css("font-size", fontsize*twice + "px");
			$(".datagrid-cell-rownumber").css("height", lineheight*twice + "px");
			$(".datagrid-cell-rownumber").css("line-height", lineheight*twice + "px");
      
    		
			$('.datagrid div').each(function(i){
				   var classname = $(this).attr('class');
				   if  ((classname != undefined) && (classname.indexOf('datagrid-')!=-1)){
				   	    var newwidth = $(this).attr("oldwidth");
				   	    
				   	    if (newwidth == undefined) {				   	    	
                    newwidth = $(this).css("width");
                    $(this).attr("oldwidth",newwidth);
                    
                }
                
                var newwidth = parseFloat(newwidth) * twice;
                if (newwidth > 0)
				   	    $(this).css('width',newwidth);
				   	}
				   	
    		});
			
			$('#cc').layout();  
		}
		}
	
	var showflag = false;
	$(document).keypress(function(e) {
	    if (e.which == 13 ) {
	    	showUnitname();
	    };
	});
	
	function showUnitname(){
		if (showflag == false){
    		$('#t-dg').datagrid('showColumn','unitname');
    	  showflag = true;
    	}else{
    		$('#t-dg').datagrid('hideColumn','unitname');
    		showflag = false;
    	}
	}
	
		$(function(){
				init();
				
				
				
		});
		
			function init(){
				$('#tt-dg').datagrid({
					loadMsg:'正在加载',
					view:bufferview,  
	                pageSize:50,
	                rownumbers:false,
	                singleSelect:true,  
	                url:'<c:url value="/read/Esexcerpt/getEsexcerptItems"/>',  
	                onDblClickRow:function(Index, row){
						$('#t-dg').datagrid('load', {
							t: row.id
						});
						
					}
				});
				
				$('#t-dg').datagrid({
					loadMsg:'正在加载',
					onLoadSuccess:function(data){
						dgfontsizechange();											
						},
						rowStyler:function(index,row){  
		                	if(row.timeout == 0){   			        	
					        	if (row.usr_op_type == '新增')
					        	    return 'background-color:${cfgs["newbgcolor"]};color:${cfgs["newfgcolor"]};font-weight:bold;';
					        	else
					        		return 'background-color:${cfgs["updbgcolor"]};color:${cfgs["updfgcolor"]};font-weight:bold;';			        	
				            } else {
				            	if(row.timeout > 182)
				            		return 'background-color:${cfgs["expbgcolor"]};color:${cfgs["expfgcolor"]};font-weight:bold;';
				            	else
				            		return 'background-color:${cfgs["ptbgcolor"]};color:${cfgs["ptfgcolor"]};font-weight:bold;';
				            }   
				        },
					view:scrollview,  
	                pageSize:50,
	                onDblClickRow:function(rowIndex, rowData){
	                	viewItem();
	                },
					onRowContextMenu:function(e,index,row){
						e.preventDefault();
						$('#t-dg').datagrid('clearSelections');
						$('#t-dg').datagrid('selectRow', index);
						$('#mm').menu('show', {
							left:e.pageX,
							top:e.pageY
						});
					}
				
			});
				
			}

		
			var actionUrl;
			function newItem(){
				$('#dlg').dialog('setTitle', '新增房源摘录').dialog('open');
				$('#myform').form('clear');
				actionUrl = '<c:url value="/read/Esexcerpt/saveEsexcerpt"/>';
			}
			function editItem(){
				var t = $('#tt-dg');
				var row = t.datagrid('getSelected');
				if (row){
					$('#myform').form('load', row);
					$('#dlg').dialog('setTitle', '修改房源摘录').dialog('open');
					actionUrl = '<c:url value="/read/Esexcerpt/updateEsexcerpt"/>?id=' + row.id;
				}
			}
			
			function deleteItem(){
				var t = $('#tt-dg');
				var row = t.datagrid('getSelected');
				if (row){
					
					$.messager.confirm('删除确认', '是否确定要删除选择房源摘录?', function(r){
							if (r){
					$.ajax({
						url:'<c:url value="/read/Esexcerpt/destroyEsexcerpt"/>?id=' + row.id,
						type:'post',
						success:function(){
							$('#tt-dg').datagrid('reload');
						}
					});
				}});
					
				}
			}
			
			function saveItem(){
				$('#myform').form('submit', {
					url:actionUrl,
					onSubmit:function(){
						return $('#myform').form('validate');
					},
					success:function(data){
						var data = eval('('+data+')');
						if (data.success){
							$('#dlg').dialog('close');
							$('#tt-dg').datagrid('reload');
						} else {
							$.messager.show({
								title:'保存失败',
								msg:'<pre>'+data.msg+'</pre>'
							});
						}
					}
				});
			}

			function move(dir){
				var row = $('#tt-dg').datagrid('getSelected');
				$.getJSON('<c:url value="/read/Esexcerpt/move"/>', {id:row.id,dir:dir}, function(){
					$('#tt-dg').datagrid('reload');
				});
			}
			
			function addItem(){
				var row1 = $('#t-dg').datagrid('getSelected');
				var row2 = $('#tt-dg').datagrid('getSelected');
				if ((row1) && (row2)) {
				$.getJSON('<c:url value="/read/Esexcerpt/addRow"/>', {id:row1.id,extid:row2.id}, function(){
					$.messager.show({
						title:'系统提示',
						msg:'选择房源['+row1.local_id+']已加入选择房源摘录。'
					});
				});
				}else{
					$.messager.show({
						title:'系统提示',
						msg:'请先选择房源摘录。'
					});
					
				}
			}
			
			function removeItem(){
				var row1 = $('#t-dg').datagrid('getSelected');
				var row2 = $('#tt-dg').datagrid('getSelected');
				if ((row1) && (row2)) {
				$.getJSON('<c:url value="/read/Esexcerpt/removeRow"/>', {id:row1.id,extid:row2.id}, function(){
					$.messager.show({
						title:'系统提示',
						msg:'选择房源['+row1.local_id+']已从选择房源摘录移走。'
					});
				});				
			    }else{
					$.messager.show({
						title:'系统提示',
						msg:'请先选择房源摘录。'
					});
					
				}
			}
			
			function showItem(){
				  $('#cc').layout('expand','east');
				
			}
			
			function hideItem(){
				
				  $('#cc').layout('collapse','east');
				
			}
			
		function doQuery(value){
			$('#t-dg').datagrid('load', {
				q: value
			});
		}
		
		function viewItemMemo(){
			var t = $('#tt-dg');
			if (isSingleSelect(t)){
			var row = t.datagrid('getSelected');
			  if (row){
				  if (row.memo)
				      $.messager.alert('摘录备注',row.memo);
				  else
					  $.messager.alert('摘录备注',"此摘录没有备注内容。"); 
			  }
		    }
		}
		
		function viewItem(){
			var t = $('#t-dg');
			if (isSingleSelect(t)){
			var row = t.datagrid('getSelected');
			if (row){
				parent.open2('<c:url value="/read/Esinfo/showEstateInfo"/>?id=' + row.id,'房源编号：'+row.local_id);
				
				
				
			}
			}
			
			
		}
		
		
		function advanceQuery(){
			
			showQueryDialog('<c:url value="/"/>','组合查询', function(data){
				$('#t-dg').datagrid('load',data);
			});
		}
		
		function advanceOrder(){
			showOrderDialog('<c:url value="/"/>','排序方式', function(data){
				$('#t-dg').datagrid({
					orderName:data.orderName,
					sortName:data.sortName
				});
			});
		}
	</script>
</head>
<body>
	<div id="cc" class="easyui-layout" fit="true">
		<div region="north" border="false" style="height:40px;padding:5px;overflow:hidden;">
		<div style="padding-top:3px;float:left"><input type="checkbox" name="" class="easyui-validatebox" onclick="showUnitname();"/></div>
		<div style="float:left;padding-top:5px">
		显示&nbsp;
		</div>
			<div style="padding-top:3px;float:left">			
			<input class="easyui-searchbox" prompt="按方式|地址进行查询" searcher="doQuery" style="width:300px"></input>
		</div>
		<div style="float:left">
		     					    
		    <a href="#" class="easyui-linkbutton" iconCls="icon-search" plain="true" onclick="advanceQuery()">组合查询</a>
		    <a href="#" class="easyui-linkbutton" iconCls="icon-search" plain="true" onclick="advanceOrder()">排序方式</a>		    		
			<a href="#" class="easyui-linkbutton" iconCls="icon-search" plain="true" onclick="viewItem()">详细信息</a>		
		</div>
	</div>
	<div data-options="region:'east',split:false,collapsed:true,title:'房源摘录'" style="width:260px;">
	<div class="easyui-layout" fit="true">
	<div data-options="region:'south',border:false" style="height:40px;padding:8px;overflow:hidden;">
	        <a href="javascript:void(0);" title="新增" class="easyui-linkbutton" iconCls="icon-application_add" plain="true" onclick="newItem()"></a>
			<a href="javascript:void(0);" title="修改" class="easyui-linkbutton" iconCls="icon-application_edit" plain="true" onclick="editItem()"></a>
			<a href="javascript:void(0);" title="删除" class="easyui-linkbutton" iconCls="icon-application_delete" plain="true" onclick="deleteItem()"></a>
			<a href="javascript:void(0);" title="上移" class="easyui-linkbutton" iconCls="icon-arrow_up" plain="true" onclick="move('up')"></a>
			<a href="javascript:void(0);" title="下移" class="easyui-linkbutton" iconCls="icon-arrow_down" plain="true" onclick="move('down')"></a>
			<a href="javascript:void(0);" title="刷新" class="easyui-linkbutton" iconCls="icon-reload" plain="true" onclick="$('#tt-dg').datagrid('reload');"></a>	
			<a href="javascript:void(0);" title="查看备注" class="easyui-linkbutton" iconCls="icon-application_view_list" plain="true" onclick="viewItemMemo();"></a>
	</div>
	<div data-options="region:'center'">
	<table id="tt-dg" style="display:none;" title=""
					
					border="false" fit="true" >
				<thead>
					<tr>
						<th field="title" width="230" sortable="true">摘录名称</th>
					</tr>
				</thead>
			</table>
	</div>
</div>
	
	
	
    </div>	
		
		<div region="center" border="true">
			<table id="t-dg" style="display:none;"
					url="<c:url value='/read/esinfo/getEstate2Items'/>"
					singleSelect="true" rownumbers="true" 
					border="false" fit="true" >
				<thead>
					<tr>
<c:if test="${fieldscount == 0 }">					
<th field="unitname" width="100" sortable="true" hidden="false">单位名称</th>					
<th field="local_id" width="100" sortable="true">房源编号</th>
<th field="selfcode" width="100" sortable="false">自编号</th>
<th field="editdate" width="100" sortable="true">录入时间</th>
<th field="mode" width="100" sortable="true">方式</th>
<th field="address" width="100" sortable="true">地址</th>
<th field="circs" width="100" sortable="true">手续</th>
<th field="purpose" width="100" sortable="true">类别</th>
<th field="layer" width="100" sortable="true">楼层</th>
<th field="direction" width="100" sortable="false">方向</th>
<th field="room" width="100" sortable="true">规格</th>
<th field="area" width="100" sortable="true">面积</th>
<th field="price" width="100" sortable="true">价格</th>
<th field="unit" width="100" sortable="false">价格单位</th>
<th field="totalprice" width="100" sortable="true">总价</th>
<th field="phone_flag" width="100" sortable="false">电话</th>
<th field="scheduled_flag" width="100" sortable="false">钥匙</th>
<th field="memo" width="100" sortable="false">备注</th>
<th field="oper" width="100" sortable="false">操作人员</th>
<th field="displayhint" width="100" sortable="true">显示限制</th>
<th field="fitment" width="100" sortable="false">装修</th>
<th field="wg" width="100" sortable="false">外观</th>
<th field="qt" width="100" sortable="false">其它</th>
<th field="sj" width="100" sortable="false">实价</th>
<th field="usr_op_type" width="100" sortable="true">信息类型</th>
</c:if>
<c:forEach items="${fields}" var="field" varStatus="status">
  <th field="${field.field}" width="${field.width}" sortable="true" 
  <c:if test="${field.ishidden==1}">
  hidden="false"
  </c:if>
  >${field.showtitle }</th>
</c:forEach>
	

					</tr>
				</thead>
			</table>
		</div>
	</div>
	

	

<div id="dlg" style="width:350px;height:200px;"
			class="easyui-dialog" closed="true" modal="true" buttons="#dlg-buttons">
		<div style="padding:10px">
			<div style="float:left">
				<form id="myform" method="post" style="margin:0;padding:0">
					<table>
<tr>
<td style="width:80px">摘录名称</td>
<td><input type="text" class="easyui-validatebox e-input" id="title" name="title" style="width:250px;" data-options="required:true,editable:true" ></input></td>
</tr>	
<tr>
<td style="width:80px">摘录备注</td>
<td><textarea type="text" class="easyui-validatebox e-input" id="memo" name="memo" style="width:250px;height:50px" data-options="required:false,editable:true" ></textarea></td>
</tr>	
								
					</table>
				</form>
			</div>			
			<div style="clear:both"></div>
		</div>
		<div id="dlg-buttons" style="text-align:center;">
			<a href="#" class="easyui-linkbutton" iconCls="icon-save" onclick="saveItem()">保存</a>
			<a href="#" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')">取消</a>
		</div>
</div>
	
<div id="mm" class="easyui-menu" style="width:120px;">
		<div iconCls="icon-add" onclick="addItem()">加入房源摘录</div>
		<div iconCls="icon-remove" onclick="removeItem()">从房源摘录移走</div>
		<div class="menu-sep"></div>
		<div onclick="showItem();">显示房源摘录</div>
		<div onclick="hideItem();">隐藏房源摘录</div>
</div>

</body>
